//
//  MainTabBar.swift
//  XYWeibo
//
//  Created by 常晓璇 on 6/23/15.
//  Copyright © 2015 chang xiaoxuan. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let barBtnCount = 5
        // 设置frame
        let w = bounds.width / CGFloat( barBtnCount)
        let rect = CGRectMake(0, 0, w, bounds.height)
        
        var index = 0
        
        for v in subviews {
            if v is UIControl && !(v is UIButton) {
                v.frame = CGRectOffset(rect, CGFloat(index) * w, 0)
                
                index += index == 1 ? 2 : 1
            }
        }
        compoesButton.frame = CGRectOffset(rect, 2 * w, 0)
    }
    
    
    lazy var compoesButton : UIButton = {
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        return btn
        }()

}


